package DuiXiang.src.Computer;

import java.util.Scanner;

public class ComputerTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Computer c = new Computer("联想S436", "红色", "1024*768");
        while (true) {
            System.out.println("1.格式化；2.安装操作系统；3.启动；4.安装软件；5.下载软件；6.查看各盘情况；9、关机；0.退出");
            int ch = input.nextInt();
            if (ch == 1) {
                if (c.isStart1()) {
                    System.out.println("计划分几个盘;");
                    int a = input.nextInt();
                    for (int i = 0; i < a; ) {
                        Disk d = new Disk();
                        boolean aa = true;
                        while (aa) {
                            System.out.println("请输入第" + (i + 1) + "个盘符名称和大小：");
                            d.setName(input.next());
                            d.setDiskSize(input.nextDouble());
                            if (!c.format(d)) {
                                System.out.println("盘符重名,请重新设置。");
                            } else {
                                aa = false;
                                i++;
                            }
                        }
                    }
                    System.out.println("格式化成功！");
                } else {
                    System.out.println("请先启动电脑。");
                }
            } else if (ch == 2) {
                if (c.isStart1() && c.isFormat1()) {
                    Software s = new Software();
                    System.out.println("请选择需要安装的操作系统\nwin7_700M / win10_800M / win11_1000M");
                    s.setName(input.next());
                    System.out.println("软件大小（M）：");
                    s.setMemory(input.nextInt());
                    System.out.println("请选择安装的盘：");
                    String p = input.next();
                    if (c.os(s, p)) {
                        System.out.println("安装成功！\n系统软件名称是" + s.getName() + "，软件大小为" + s.getMemory());
                    } else {
                        System.out.println("安装失败！");
                    }
                    //                  }
                } else if (!c.isFormat1() && c.isStart1())
                    System.out.println("请先格式化电脑");
                else
                    System.out.println("请先启动电脑并格式化");
            } else if (ch == 3) {
                c.start();
            } else if (ch == 4) {
                if (c.isStart1() && c.isFormat1() && c.isOs1()) {
                    System.out.println("1、普通软件；2、下载软件");
                    int a = input.nextInt();
                    System.out.println("软件名称：");
                    String na = input.next();
                    System.out.println("软件大小（M）：");
                    double m = input.nextDouble();
                    System.out.println("安装位置：");
                    String n = input.next();
                    if (a == 1) {
                        Software s = new Software();
                        s.setName(na);
                        s.setMemory(m);
                        if (c.add(n, s)) {
                            System.out.println("安装成功");
                        } else {
                            System.out.println("安装失败");
                        }
                    } else {
                        BitComet bi = new BitComet();
                        bi.setName(na);
                        bi.setMemory(m);
                        if (c.addSoftware(n, bi)) {
                            System.out.println("安装成功");
                        } else {
                            System.out.println("安装失败");
                        }
                    }

                } else if (!c.isFormat1() && c.isStart1())
                    System.out.println("请先格式化电脑");
                else if (!c.isOs1() && c.isFormat1())
                    System.out.println("请先安装操作系统");
                else
                    System.out.println("请先启动电脑");
            } else if (ch == 5) {
                if (c.isStart1() && c.isFormat1() && c.isOs1()) {
                    System.out.println("请选择一个下载软件：");
                    c.showBitComet();
                    String na = input.next();
                    if (c.xiaZai(na))
                        System.out.println(na + "启动成功");
                    else {
                        System.out.println("没有您选择的下载软件");
                        break;
                    }
                    System.out.println("输入需要下载的软件名称和大小：");
                    String xna = input.next();
                    double d = input.nextDouble();
                    System.out.println("请选择安装盘：");
                    String p = input.next();
                    Software s = new Software(xna, d);
                    if (c.add(p, s)) {
                        System.out.println("安装成功");
                    } else {
                        System.out.println("安装失败");
                    }
                } else if (!c.isFormat1() && c.isStart1())
                    System.out.println("请先格式化电脑");
                else if (!c.isOs1() && c.isFormat1())
                    System.out.println("请先安装操作系统");
                else
                    System.out.println("请先启动电脑");
            } else if (ch == 6) {
                if (c.isStart1() && c.isFormat1() && c.isOs1()) {
                    System.out.println("请选择需要查看的盘符：");
                    c.showDisk(input.next());
                } else if (!c.isFormat1() && c.isStart1())
                    System.out.println("请先格式化电脑");
                else if (!c.isOs1() && c.isFormat1())
                    System.out.println("请先安装操作系统");
                else
                    System.out.println("请先启动电脑");
            } else if (ch == 9) {
                System.out.println("关机");
                c.shutDown();
            } else if (ch == 0) {
                System.out.println("退出");
                return;
            }
        }
    }
}
